package core;

import redis.clients.jedis.Jedis;

import java.time.LocalDate;

public class SignInImpl implements SignIn {

    public boolean clockIn(int id) {
        Jedis jedis = Properties.getInstance().getResource();
        try {
            return jedis.setbit(buildSignKey(id) ,LocalDate.now().getDayOfMonth(),true);
        } finally {
            jedis.close();
        }
    }

    private static String buildSignKey(int uid) {
        return String.format("u:sign:%d:%d", uid, LocalDate.now().getMonthValue());
    }
}
